package org.tln.db137.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.tln.db137.common.R;
import org.tln.db137.entity.Userrole;
import org.tln.db137.service.UserroleService;

@RestController
@CrossOrigin("*")
public class UserRoleController {
    @Autowired
    private UserroleService userroleService;

    @PostMapping("/deleteByUserIdAndRoleId")
    public R deleteByUserIdAndRoleId(@RequestBody Userrole userrole) {
        UpdateWrapper<Userrole> wrapper = new UpdateWrapper<>();
        wrapper.setEntity(userrole);
        this.userroleService.remove(wrapper);
        return new R();
    }
    @PostMapping("/addByUserIdAndRoleId")
    public R addByUserIdAndRoleId(@RequestBody Userrole userrole) {
        this.userroleService.save(userrole);
        return new R();
    }

}
